package com.asiainfo.lop;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @Description:gridview的Adapter
 */
public class MyselfGridAdapter extends BaseAdapter {
    private Context mContext;

    public String[] img_text = {"我的任务", "我的好友", "实时位置", "", "", "", "", "", ""};
    public int[] imgs = {R.drawable.myself_icon_task, R.drawable.myself_icon_friend, R.drawable.myself_icon_friend};

    public MyselfGridAdapter(Context mContext) {
        super();
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return img_text.length;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.grid_item, parent, false);
        }
        TextView tv = BaseViewHolder.get(convertView, R.id.tv_item);
        ImageView iv = BaseViewHolder.get(convertView, R.id.iv_item);
        if(position < imgs.length){
            iv.setBackgroundResource(imgs[position]);
        }

        tv.setText(img_text[position]);
        tv.setTag(position);

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TextView tv = BaseViewHolder.get(v, R.id.tv_item);
                String pos = tv.getTag() + "";
                switch (pos){
                    case "2":{
                        Intent intent = new Intent(mContext, LocActivity_.class);
                        mContext.startActivity(intent);
                        break;
                    }
                    default:{
                        Toast.makeText(mContext, "当前功能暂未开放", Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });

        return convertView;
    }

    static class viewHolder{
        public ImageView imgIv;
        public TextView nameTV;
    }

}
